package com.dongdong.controller;


import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.dongdong.result.Result;
import com.dongdong.result.ResultEnums;
import com.dongdong.service.SeckillGoodsService;
import com.dongdong.vo.SeckillGoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("seckillGoods")
@Component   //定时任务
public class SeckillGoodsController {

    @Autowired
    private SeckillGoodsService seckillGoodsService;



    //缓存预热
    @Scheduled(cron = "0 0 14 * * ? ")
    @GetMapping("getRedisHot")
    public Result getRedisHot(){

       seckillGoodsService.getRedisHot();
        return Result.RESPONSE(ResultEnums.HOT_SUCCESS);

    }




     //获取redis中的数据
      @GetMapping("/findSeckillGoodsList")
      public Result findSeckillGoodsList() {
          List<SeckillGoodsVO> seckillGoodsVOS = seckillGoodsService.findSeckillGoodsList();
          return Result.OK().setData(seckillGoodsVOS);

      }

    //根据秒杀商品的id查询商品信息
    @GetMapping("/selectSeckillById")
    public Result selectSeckillById(@RequestParam Long id){
        SeckillGoodsVO seckillGoodsVO=  seckillGoodsService.selectSeckillById(id);
        return Result.OK().setData(seckillGoodsVO);
    }

    //查看秒杀商品
    @GetMapping("/getSeckillGoodsVO")
    public Result getSeckillGoodsVO(@RequestParam Long id){
        SeckillGoodsVO seckillGoodsVO=  seckillGoodsService.getSeckillGoodsVO(id);
        return Result.OK().setData(seckillGoodsVO);
    }





}
